﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Text;
using System.Net.Mail;

/// <summary>
/// WebService 的摘要描述
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從指令碼呼叫此 Web 服務，請取消註解下一行。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //如果使用設計的元件，請取消註解下行程式碼 
        //InitializeComponent(); 
    }


    [WebMethod]
    public void sendMail(Mail mail)
    {

        string smtpServer = "smtp.gmail.com";
        int smtpPort = 587;

        string username = "qooliliyahoo.com.tw@gmail.com";
        string password = "qo0hank";

        MailMessage mailMessage = new MailMessage();

        mailMessage.From = new MailAddress(mail.sender);
        mailMessage.To.Add(new MailAddress(mail.receiver));

        mailMessage.Subject = mail.subject;
        mailMessage.SubjectEncoding = Encoding.UTF8;

        mailMessage.Body = mail.message;
        mailMessage.BodyEncoding = Encoding.UTF8;

        SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort);

        smtpClient.Credentials = new System.Net.NetworkCredential(username, password);
        smtpClient.EnableSsl = true;

        smtpClient.Send(mailMessage);

    }

}

public class Mail
{
    public string sender;
    public string receiver;
    public string subject;
    public string message;
}